package com.teachoa.bean;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.teachoa.util.IDUtil;

public class UserMsg extends Model<UserMsg> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5699626144702106555L;
	public static final UserMsg dao = new UserMsg(); 
	
	public List<UserMsg> getMsgUsers(String msgId) {
		return dao.find("select * from user_msg where msg_id = ?", msgId);
	}
	
	public void updateRelation(String msgId, String[] userIds) {
		Db.update("delete from user_msg where msg_id = ?", msgId);
		for(String id:userIds) {
			UserMsg um = new UserMsg();
			um.set("id", IDUtil.getId());
			um.set("msg_id", msgId);
			um.set("user_id", id);
			um.save();
		}
	}

}
